package com.cn.Spring.Contoller;

import org.apache.ibatis.session.SqlSession;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {

    @RequestMapping(value = "/login")
    public String loginPage() {

        return "welcome";
    }

    @RequestMapping(value = "/login1.html")
    public String loginCheck(String UserId,String password) throws Exception {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        SqlSession session = (SqlSession) ctx.getBean("sqlsessionTemplate");
//
////        User user1 = session.selectOne("findById", 1);
//        String user1 = session.selectOne("findById", 1);
        String user1 = session.selectOne("findById",1);
//        System.out.print(user1.getUserId());
        System.out.print(user1);
        System.out.print(password);
        if (user1.equals(password)) {
            return ("Successful");
        }else {
            return ("Error");
        }
////        if ((user1.getUserId() == user.getUserId()) && (user1.getPassword() == user.getPassword())) {
////            return new ModelAndView("Successful");
////        } else {
////            return new ModelAndView("Error");
////        }
//        return "Successful";
    }
}
